//二分查找
public class BinarySearchR {
    private BinarySearchR() {
    }

    public static <E extends Comparable<E>> int search(E[] data, E target) {
        return search(data, target, 0, data.length - 1);
    }

    //递归实现二分查找
    private static <E extends Comparable<E>> int search(E[] data, E target, int l, int r) {
        if (l > r) {
            return -1;
        }
        int mid = (l + r) / 2;
        if (data[mid].compareTo(target) > 0) {
            return search(data, target, l, mid - 1);
        } else if (data[mid].equals(target)) {
            return mid;
        }
        return search(data, target, mid + 1, r);
    }


}
